import 'package:flutter/material.dart';
import 'package:homepad/logger/logger.dart';
import 'package:homepad/models/nova_model.dart';
import 'package:homepad/screens/panel_service.dart';
import 'package:homepad/views/item_setting_air_conditioner.dart';

import 'package:homepad/widgets/home_widget_main.dart';
import 'package:homepad/widgets/home_widget_calendar.dart';
import 'package:homepad/widgets/home_widget_photo.dart';
import 'package:homepad/widgets/home_widget_external.dart';

import 'package:homepad/views/item_setting.dart';
import 'package:homepad/views/item_setting_detail.dart';
import 'package:provider/provider.dart';

class PageHome extends StatelessWidget {
  const PageHome({super.key});

  @override
  Widget build(BuildContext context) {
    String home = context.read<NovaModel>().config.home;
    int serviceSize = context.read<NovaModel>().config.nodes.where((item) => item.icon != null).length;

    return Scaffold(
        backgroundColor: Colors.black,
        body: Container(
            margin: const EdgeInsets.all(5),
            padding: const EdgeInsets.all(20).copyWith(bottom: 15),
            child: Stack(
              children: [
                const Row(
                  children: [
                    Column(
                      children: [
                        HomeWidgetMain(),
                      ],
                    ),
                    SizedBox(width: 20),
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        HomeWidgetPhoto(),
                        SizedBox(height: 20),
                        Row(
                          children: [
                            HomeWidgetCalendar(),
                            SizedBox(width: 20),
                            HomeWidgetExternal(),
                          ],
                        )
                      ],
                    )
                  ],
                ),
                Positioned(
                    left: 0,
                    bottom: 0,
                    child: Row(
                      children: [
                        SettingItemDetail(
                            "icon_setting_home",
                            title: home,
                            subtitle: "$serviceSize个设备",
                            onPressed: () {
                              logger.info("tapped");
                              showDialog(
                                  context: context,
                                  builder: (context) => Dialog.fullscreen(
                                    child: PanelService(onCancel: () {
                                      Navigator.pop(context);
                                    }),
                                  ));
                            },
                        ),
                        const SizedBox(width: 10),
                        const ItemSettingAirConditioner(),
                      ],
                    )),
                const Positioned(
                    right: 0,
                    bottom: 0,
                    child: Row(
                      children: [
                        SettingItem("assets/images/icon_setting_matter.jpg"),
                        SizedBox(width: 10),
                        SettingItem("assets/images/icon_setting_wifi.jpg"),
                        SizedBox(width: 10),
                        SettingItem("assets/images/icon_settings.jpg"),
                      ],
                    ))
              ],
            )));
  }
}
